public class lk6257 {
    public static void main(String[] args) {
        int[][] grid = new int[][]{{1,2,4},{3,3,1}} ;
        System.out.println(deleteGreatestValue(grid));
    }
    public static int deleteGreatestValue(int[][] grid) {
        int n1= grid.length;
        int n2 = grid[0].length;
        int[] s=new int[2];
        int end=0,max=0;
        int smax=0;
        int j=0,q=0;
        for(int i=0;i<n2;i++){
            for(q=0;q<n1;q++){
                smax=0; 
                for(j=0;j<n2;j++){
                    if(grid[q][j]>smax)
                    {
                        smax=grid[q][j];
                        s[0]=q;
                        s[1]=j;
                    }
                }
                grid[s[0]][s[1]]=0;
                if(smax>max){
                    max=smax;
                }
            }
            end+=max;
            max=0;
            
        }
        return end;
    }
}
